package jwdt.xadmin.rskq.service.impl;

import jwdt.common.dao.BaseDao;
import jwdt.xadmin.rskq.bean.TKqdj;
import jwdt.xadmin.rskq.service.KqdjManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.util.DateUtil;
import com.ezerg.util.StringUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;

public class KqdjManageServiceImpl implements KqdjManageService {

	private BaseDao<TKqdj> baseDao;
	
	public void setBaseDao(BaseDao<TKqdj> baseDao) {
		this.baseDao = baseDao;
	}
	
	@Override
	public PageUtil doList(PageUtil pu, TKqdj tc ,String flag) throws Exception{
		Jdb jdb = Jdb.get();
		String where = "";
		String recorddate = tc.getRecorddate();
		String bz = tc.getBz();
		String id = tc.getId();
		if(!StringUtil.nullOrBlank(bz)) {
			TKqdj obj = (TKqdj)jdb.get(TKqdj.class, id);
			obj.setBz(bz);
			baseDao.doUpdateObj(TKqdj.class,id,obj);
		}
		if(!StringUtil.nullOrBlank(recorddate)) {
			where += " recorddate='"+recorddate+"'";
		}
		if(!StringUtil.nullOrBlank(flag)) {
			if(!StringUtil.nullOrBlank(recorddate)){where+=" and";}
			where += " flag='"+flag+"'";
		}
		String sql = " order by id desc";
		pu.doList(TKqdj.class,where+sql);
		//创造json数据对象
		return pu;
	}
	
	
	@Override
	public String kqdjbz(Form f, Module m,Integer id,String bz) throws Exception{
		Jdb jdb = Jdb.get();
		TKqdj obj = (TKqdj) jdb.get(TKqdj.class, id);
		obj = (TKqdj) f.copy2Obj(obj);
		obj.setBz(bz);
		return baseDao.doUpdateObj(TKqdj.class,id,obj);
	}
	

	@Override
	public String kqdjsbsj(TKqdj obj) throws Exception{
		return baseDao.doAddObj(obj);
	}
	
	@Override
	public String kqdjxbsj(Form f,String nowDate) throws Exception{
		Jdb jdb = Jdb.get();
		int id = jdb.queryForInt("select id from t_kq_dj where recorddate=?",new Object[]{nowDate});
		TKqdj obj = (TKqdj) jdb.get(TKqdj.class, id);
		obj.setSigndatetime2(DateUtil.getDateTime());
		return baseDao.doUpdateObj(TKqdj.class,id,obj);
	}
	
	@Override
	public String kqdjEditact(TKqdj obj,int id) throws Exception{		
		return baseDao.doUpdateObj(TKqdj.class,id,obj);
	}
}
